package com.cloud.code.算法.线性查找法;

//java 8大基本类型：  byte  ,short , int ,lang  ,char , float  ,boolean , double

import com.cloud.code.算法.ArrayGeneator;

public class LinearSearch {

    private LinearSearch() {

    }

    public static void main(String[] args) {

        int n = 1000000;

        Integer[] integers = ArrayGeneator.generatorOrderArray(n);

        long startTime = System.nanoTime();
        search(integers,n);
        long endTime = System.nanoTime();

        double time = (endTime - startTime) / 1000000000.0;

        System.out.println(time);


//        Integer[] data = {1, 2, 4, 6, 3};
//
//        String[] data2 = {"asd", "fwe", "cww", "a"};
//        int a = search(data2, "a");
//        System.out.println(a);
//
//        int search = search(data, 3);
//        System.out.println(search);
//
//        User user1 = new User("xiaoli");
//        User user2 = new User("xiaoming");
//        User user3 = new User("xiaohua");
//
//        User[] users = new User[3];
//        users[0] = user1;
//        users[1] = user2;
//        users[2] = user3;
//
//        int search1 = search(users, user1);
//        System.out.println(search1);
    }


    public static <E> int search(E[] data, E target) {
        for (int i = 0; i < data.length; i++) {
            if (data[i].equals(target))
                return i;
        }
        return -1;
    }
}
